package com.desksoft.ecommerce.aop;


import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.aspectj.lang.ProceedingJoinPoint;
import org.codehaus.jackson.map.ObjectMapper;

/**
 * 记录日志  #{sadfasdf}
 * @author foever
 *
 */
public class TimeHandleAdvice {

	private Logger logger = Logger.getLogger(this.getClass().getName());
	
	public Object timerAround(ProceedingJoinPoint jointpoint) throws Throwable{
		long procTime = System.currentTimeMillis();
		Object result = jointpoint.proceed(); 
		ObjectMapper mapper = new ObjectMapper();
		procTime = System.currentTimeMillis() - procTime;
		String argString = null ;
		if(procTime < 100){
			
			return result;
		}
		try{
			argString = mapper.writeValueAsString(jointpoint.getArgs());
		}catch (Exception e) {
			//
		}
		logger.log(Level.ERROR, jointpoint.getTarget().getClass().getName()+" invoke " + jointpoint.getSignature().getName() + " with " + procTime + " milliseconds" + "------------args:"+argString);
		return result;
	}
}
